<%@page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@include file="/common/session.jsp"%>
<c:set var="regionId" value="${param.regionId}"/>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=2.0, user-scalable=no, width=device-width">
    <LINK type="text/css" rel="stylesheet" href="${ctx}/css/default.css"/>
    <script type="text/javascript" src="${ctx}/js/xtable.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/engine.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/util.js"></script>
    <script type='text/javascript' src='${ctx}/dwr/interface/ShopRpcService.js'></script>
    <script type='text/javascript' src='${ctx}/dwr/interface/MarketRpcService.js'></script>
    <script type='text/javascript' src='${ctx}/dwr/interface/ContractRegionRpcService.js'></script>
    <script type="text/javascript" src="${ctx}/js/loading.js"></script>
</head>
<body>
<form>
    <center>
        <input type="hidden" id="regionId" name="regionId" value="${regionId}">
        <table style="width: 50%;" cellpadding="5" cellspacing="5">
            <tr>
                <td>
                    <select id="marketId" name="marketId" onchange="getShopList()">
                    </select>
                </td>
                <td>
                    <select id="shopId" name="shopId" onchange="getRegionContractPage()">
                    </select>
                </td>
                <td>
                    <p>
                        <button type="button" onclick="callbackRegionList()">返回</button>
                    </p>
                </td>
            </tr>
        </table>
    </center>
</form>

<SCRIPT LANGUAGE="JavaScript" >
    var regionContractThead = new Array(
        new XThead("车商名称"),
        new XThead("负责人"),
        new XThead("联系电话"),
        new XThead("区域名称"),
        new XThead("租赁类型"),
        new XThead("区域面积/车位数"),
        new XThead("每月单位租金(元)"),
        new XThead("合计租金(元)"),
        new XThead("合同开始日期"),
        new XThead("合同终止日期"),
        new XThead("市场名称")
    );

    var type_hash = {
        "1":"按面积",
        "2":"按车位"
    }
    var  type_unit = {
        "1": '平米',
        "2": '个'
    }

    var regionContractXTable = new XTable("regionContract", regionContractThead, true);

    regionContractXTable.XTbodyArray = function (model) {

        var array = new Array(
            new XTbody("regionContract", model.contract.shop.shopName),
            new XTbody("regionContract", model.contract.shop.shopLegalName),
            new XTbody("regionContract", model.contract.shop.shopLegalMobile),
            new XTbody("regionContract", model.region.regionName),
            new XTbody("regionContract", type_hash[model.region.regionType]),
            new XTbody("regionContract", model.contractRegionRentCount + type_unit[model.region.regionType]),
            new XTbody("regionContract", model.contractRegionRentFee),
            new XTbody("regionContract", model.contractRegionAmount),
            new XTbody("regionContract", model.contract.contractStartDate.Format("yyyy-MM-dd"), "string", null, null, "center"),
            new XTbody("regionContract", model.contract.contractEndingDate.Format("yyyy-MM-dd"), "string", null, null, "center"),
            new XTbody("regionContract", model.region.market.marketName)
        );
        return array;
    }

    function getRegionContractPage() {
        var regionContract = new ContractRegion();
        regionContract.contract = new Contract();
        regionContract.contract.shopId = dwr.util.getValue("shopId");
        regionContract.regionId = dwr.util.getValue("regionId");
        regionContract.contract.marketId = dwr.util.getValue("marketId");
        regionContract.contractRegionState = 1;
        ContractRegionRpcService.selectContractRegionList(regionContract, function (list) {
            regionContractXTable.addTable(list);
        });
    }
</SCRIPT>
</body>
</html>
<script>

    //    显示市场列表
    var market = new Market();
    market.marketId = "${marketId}";
    MarketRpcService.selectMarketList(market, callbackSelectMarketList);

    function callbackSelectMarketList(list) {
        dwr.util.addOptions("marketId", list, "marketId", "marketName");
        dwr.util.setValue("marketId", "${marketId}");
        getShopList();
        getRegionContractPage();
    }


    function getShopList(){
        var shop = new Shop();
        shop.marketId = dwr.util.getValue("marketId");
        shop.shopState = "1";
        ShopRpcService.selectShopList(shop, callbackSelectShopList);
    }

    function callbackSelectShopList(list) {
        dwr.util.removeAllOptions("shopId");
        dwr.util.addOptions("shopId", {"" : "请选择"});
        dwr.util.addOptions("shopId", list, "shopId", "shopName");
        if('${shopId}' != "" && '${shopId}'.length > 0){
            dwr.util.setValue("shopId", "${shopId}");
        }
        getRegionContractPage();
    }



    function callbackRegionList(){
        location = "${ctx}/market/region_list.jsp";
    }

</script>
